<template>
	<view class="recordBox" style="padding: 30rpx;">
		
		<view class="recordItem" >
			<view class="title">就诊人</view>
			<view class="contentList">
				<view class="contentItem">
					<view class="label">姓名</view>
					<view class="value">{{user2.realName}}</view>
				</view>
				<view class="contentItem">
					<view class="label">年龄</view>
					<view class="value">{{user2.age}}</view>
				</view>
				<view class="contentItem">
					<view class="label">性别</view>
					<view class="value">{{user2.sex == 1?'男':'女'}}</view>
				</view>
				<view class="contentItem">
					<view class="label">就诊科室</view>
					<view class="value">{{data.deptName}}</view>
				</view>
			</view>
		</view>
		
		<view class="recordItem" >
			<view class="title">病历填写</view>
			<view class="contentList">
				<view class="">
					<view class="label">主诉</view>
					<view class="value">
						<u--textarea v-model="record.chiefComplaint" placeholder="请输入内容" ></u--textarea>
					</view>
				</view>
				<view class="">
					<view class="label">现病史</view>
					<view class="value"><u--textarea v-model="record.presentIllness" placeholder="请输入内容" ></u--textarea></view>
				</view>
				<view class="">
					<view class="label">既往史</view>
					<view class="value"><u--textarea v-model="record.pastHistory" placeholder="请输入内容" ></u--textarea></view>
				</view>
				<view class="">
					<view class="label">过敏史</view>
					<view class="value"><u--textarea v-model="record.allergyHistory" placeholder="请输入内容" ></u--textarea></view>
				</view>
				<view class="">
					<view class="label">客观记录</view>
					<view class="value"><u--textarea v-model="record.objectiveRecord" placeholder="请输入内容" ></u--textarea></view>
				</view>
				<view class="">
					<view class="label">辅助检查</view>
					<view class="value"><u--textarea v-model="record.examination" placeholder="请输入内容" ></u--textarea></view>
				</view>
				<view class="">
					<view class="label">诊断评估</view>
					<view class="value"><u--textarea v-model="record.diagnosis" placeholder="请输入内容" ></u--textarea></view>
				</view>
				<view class="">
					<view class="label">治疗计划</view>
					<view class="value"><u--textarea v-model="record.treatmentPlan" placeholder="请输入内容" ></u--textarea></view>
				</view>
				<view class="">
					<view class="label">处方</view>
					<view class="value">
						<view style="padding: 20rpx; font-size: 30rpx;color:cornflowerblue;" @click="showMedSel=true">点击添加药品</view>
						<view style="padding: 20rpx;" @click="delMed(index)" v-for="(item,index) in selMedList" :key="index">
							{{item.medName}}(点击取消药品)
						</view>
					</view>
				</view>
			</view>
		</view>
		
		
		<view class="addButton" @click="subData">
			提交
		</view>
		
		<u-action-sheet :actions="medList" @select="selectClick" title="选择药品" :show="showMedSel"></u-action-sheet>
		
		
	</view>
</template>

<script>
	import appRequest from "@/common/appRequestUrl.js";
	export default {
		data() {
			return {
				showMedSel:false,
				medList:[],
				data:{},
				user2:{uid:0},
				selMedList:[],
				record:{
					chiefComplaint:"",// 主诉
					presentIllness:"",// 现病史
					pastHistory:"",// 既往史
					allergyHistory:"",// 过敏史
					objectiveRecord:"",// 客观记录
					examination:"",// 辅助检查
					diagnosis :"",//诊断评估
					treatmentPlan:"",// 治疗计划
					preFk:"",// 处方
				},
				user:{}
			};
		},onLoad:function(options){
			this.user = appRequest.getUserInfo();
			if(!this.user){
				uni.redirectTo({
					url:"/pages/login/login"
				})
			}
			this.data = JSON.parse(options.param);
			this.getUser();
			this.getMed();
		},methods: {
			delMed(index){
				this.selMedList.splice(index, 1);
			},
			selectClick(res){
				this.selMedList.push(res);
				this.showMedSel = false;
			},
			getMed(){
				let _this = this;
				appRequest.request({
					method: "POST",
					data: {
						validFlag:1
					},
					url: appRequest.urlMap.findNmHospitalMedicineList,
					success: function(res) {
						if(res.data.code == 200){
							_this.medList = res.data.data;
							_this.medList.map(function(item,index){
								item['name'] = item.medName;
								item['subname'] = item.price+"元";
							})
						}else{
							_this.$api.msg(res.data.msg);
						}
					},
					fail: function(res) {
						_this.$api.msg("请求异常");
					}
				})
			},
			getUser(){
				let _this = this;
				appRequest.request({
					method: "POST",
					data: {
						uid:this.data.usrFk
					},
					url: appRequest.urlMap.findSysUser,
					success: function(res) {
						if(res.data.code == 200){
							_this.user2 = res.data.data;
						}else{
							_this.$api.msg(res.data.msg);
						}
					},
					fail: function(res) {
						_this.$api.msg("请求异常");
					}
				})
			},
			subData(){

				if(!this.record.allergyHistory||
				!this.record.chiefComplaint||
				!this.record.diagnosis||
				!this.record.examination||
				!this.record.objectiveRecord||
				!this.record.pastHistory||
				!this.record.presentIllness||
				!this.record.treatmentPlan){
					this.$api.msg("请填写完整");
					return;
				}
				this.record['medList'] = this.selMedList;
				this.record.userFk = this.data.usrFk;
				this.record.regFk = this.data.id;
				this.record.state = 0;
				let _this = this;
				appRequest.request({
					method: "POST",
					data:this.record,
					url: appRequest.urlMap.addNmMedicalRecord,
					success: function(res) {
						if(res.data.code == 200){
							_this.changeReg();
							uni.showModal({
								title:"信息",
								content:"诊疗结束",
								success:function(){
									uni.reLaunch({
										url:"/pages/index/index"
									})
								}
							})
						}else{
							_this.$api.msg(res.data.msg);
						}
					},
					fail: function(res) {
						_this.$api.msg("请求异常");
					}
				})
				
				
			},changeReg(){
				let _this = this;
				this.data.state = 2;
				appRequest.request({
					method: "POST",
					data: this.data,
					url: appRequest.urlMap.editNmHosiptalRegister
				})
			}
		}
	}
</script>

<style lang="scss">
			.mainView {
				border-radius: 8px;
				box-shadow: 2px 2px 5px 1px lightgray;
			}
			.recordBox{
				height: 100%;
				padding: 0 40rpx;
				.recordItem{
					margin-top: 20rpx;
					background-color: #FFFFFF;
					.title{
						height: 66rpx;
						padding: 0 20rpx;
						line-height: 66rpx;
						background: #E1E1E1;
						font-size: 32rpx;
						color: #141414;
					}
					.contentList{
						display: flex;
						flex-direction: column;
						font-size: 28rpx;
						color: #6D6D6D;
						.contentItem{
							display: flex;
							align-items: center;
							justify-content: space-between;
							border-bottom: 1px dashed #C1C1C1;
							height: 66rpx;
							padding: 0 20rpx;
							line-height: 66rpx;
						}
					}
					.showDetail{
						color: #548AFB;
						padding: 20rpx 0;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}
			}
			.addButton {
				width: 490rpx;
				height: 84rpx;
				margin: 100rpx auto 0;
				background: linear-gradient(90deg, #5088FD 0%, #62B9F9 100%);
				border-radius: 12rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
				font-size: 40rpx;
				letter-spacing: 4rpx;
			}
</style>
